home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
- PRODUCT : Delphi NUMBER : 2859
- VERSION : All
- OS : Windows
- DATE : August 23, 1995 PAGE : 1/2
-
- TITLE : How to do bit-wise manipulation.
-
-
-
-
- Q: How do I do bit-wise manipulation?
-
- A:
-
- {******************************************
- TheBit parameter is counted from 0..31
- ******************************************}
-
- unit Bitwise;
-
- interface
- function IsBitSet(const val: longint; const TheBit: byte): boolean;
- function BitOn(const val: longint; const TheBit: byte): LongInt;
- function BitOff(const val: longint; const TheBit: byte): LongInt;
- function BitToggle(const val: longint; const TheBit: byte): LongInt;
-
-
-
- implementation
-
- function IsBitSet(const val: longint; const TheBit: byte): boolean;
- begin
- result := (val and (1 shl TheBit)) <> 0;
- end;
-
- function BitOn(const val: longint; const TheBit: byte): LongInt;
- begin
- result := val or (1 shl TheBit);
- end;
-
- function BitOff(const val: longint; const TheBit: byte): LongInt;
- begin
- result := val and ((1 shl TheBit) xor $FFFFFFFF);
- end;
-
- function BitToggle(const val: longint; const TheBit: byte): LongInt;
- begin
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PRODUCT : Delphi NUMBER : 2859
- VERSION : All
- OS : Windows
- DATE : August 23, 1995 PAGE : 2/2
-
- TITLE : How to do bit-wise manipulation.
-
-
-
-
- result := val xor (1 shl TheBit);
- end;
-
- end.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- DISCLAIMER: You have the right to use this technical information
- subject to the terms of the No-Nonsense License Statement that
- you received with the Borland product to which this information
- pertains.
-